﻿using System;
using System.Windows.Data;
using BizControl.Library.BusinessObjects.Marks;
using System.Windows.Media;
using System.Windows.Shapes;
using BizControl.Library.BusinessObjects.Activities;

namespace BizControl.Presentation.ActivityEditModule.Converters
{
  public class ConditionTypeToNameConverter : IMultiValueConverter
  {
    private readonly int TypeIndex = 0;
    private readonly int MarkIndex = 1;
    private readonly int ActivityIndex = 2;

    public bool IsNameVeryShort { get; set; }

    public ConditionTypeToNameConverter()
    {
      IsNameVeryShort = false;
    }

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      var type = (ConditionType)Enum.Parse(typeof(ConditionType), values[TypeIndex].ToString());
      if (type == ConditionType.ActivityRequired)
      {
        if ((values[ActivityIndex] as ActivityInfo) != null)
          if (IsNameVeryShort)
            return (values[ActivityIndex] as ActivityInfo).VeryShortDescription;
          else
            return (values[ActivityIndex] as ActivityInfo).ShortenDescription;
      }
      if (type == ConditionType.MarkRequired || type == ConditionType.SkillRequired)
      {
        if ((values[MarkIndex] as MarkInfo) != null) 
          if (IsNameVeryShort)
            return (values[MarkIndex] as MarkInfo).VeryShortName;
          else
            return (values[MarkIndex] as MarkInfo).Name;
      }
      return Infrastructure.Properties.Captions.EmptyValue;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
      return null;
    }

    #endregion
  }
}
